package top.zuli.package03.exam01;

public class Singleton {
    /*//1.私有构造器
    private Singleton(){}
    //2.静态对象属性，只有一份
    private static Singleton singleton = new Singleton();
    //3.提供方法，调用对象
    public static  Singleton getSingleton(){
        return singleton;
    }

    public static void main(String[] args) {
        Singleton singleton1 = Singleton.getSingleton();
        Singleton singleton2 = Singleton.getSingleton();
        System.out.println(singleton1==singleton2);
    }*/

    /*private Singleton(){}
    private static Singleton singleton = new Singleton();
    public static Singleton getSingleton(){
        return singleton;
    }

    public static void main(String[] args) {
        Singleton singleton1 = Singleton.getSingleton();
        Singleton singleton2 = Singleton.getSingleton();
        System.out.println(singleton1==singleton2);
    }*/

    private Singleton(){}
    private static Singleton singleton = new Singleton();
    public static Singleton getSingleton(){
        return singleton;
    }

    public static void main(String[] args) {
        Singleton singleton1 = Singleton.getSingleton();
        Singleton singleton2 = Singleton.getSingleton();
        System.out.println(singleton1==singleton2);
    }
}
